VERSION 5.00
Begin VB.Form Form2 
   BackColor       =   &H0013E1A4&
   Caption         =   "History"
   ClientHeight    =   6735
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   8640
   LinkTopic       =   "Form2"
   ScaleHeight     =   6735
   ScaleWidth      =   8640
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command3 
      Caption         =   "Delete All"
      Height          =   495
      Left            =   6960
      TabIndex        =   7
      Top             =   5880
      Width           =   1455
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Delete"
      Height          =   495
      Left            =   5280
      TabIndex        =   6
      Top             =   5880
      Width           =   1455
   End
   Begin VB.ComboBox Combo1 
      Height          =   315
      Left            =   120
      TabIndex        =   4
      Top             =   1560
      Width           =   2175
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Get History"
      Height          =   495
      Left            =   480
      TabIndex        =   2
      Top             =   6000
      Width           =   1455
   End
   Begin VB.TextBox Text1 
      Appearance      =   0  'Flat
      BorderStyle     =   0  'None
      Height          =   3855
      Left            =   3720
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   1
      Top             =   1680
      Width           =   4815
   End
   Begin VB.ComboBox Combo2 
      Appearance      =   0  'Flat
      Height          =   315
      Left            =   120
      TabIndex        =   0
      Top             =   2520
      Width           =   2175
   End
   Begin VB.Shape Shape1 
      BackStyle       =   1  'Opaque
      BorderStyle     =   0  'Transparent
      Height          =   7095
      Left            =   2880
      Top             =   -360
      Width           =   5775
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "My name"
      Height          =   255
      Left            =   120
      TabIndex        =   5
      Top             =   1320
      Width           =   2175
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Enter Peer Name"
      Height          =   375
      Left            =   120
      TabIndex        =   3
      Top             =   2280
      Width           =   2175
   End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim r, d As String
Dim cnt As Integer

Private Sub Command1_Click()
Text1.text = ""
Main
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "SELECT * from table2 WHERE (chat_from = '" & Combo1.text & "' AND chat_to ='" & Combo2.text & "' ) OR (chat_from='" & Combo2.text & "' AND chat_to='" & Combo1.text & "')", con, adOpenDynamic, adLockOptimistic
If Myname = Combo2.text Then

Combo2.text = ""
MsgBox ("INVALID INPUT")
End If

cnt = rs.RecordCount

If rs.BOF = True And rs.EOF = True Then
If (Combo2.text = "") Then
Text1.text = "They haven't chatted even once , so far!"
End If
Else
If rs.EOF = False Then
d = CStr(rs!Date1)
Text1.text = d & vbCrLf
While rs.EOF = False

If (rs!Date1 = d) Then
r = (rs!chat_from) & vbCrLf & CStr(rs!Time1) & vbCrLf & (rs!messege)
Text1.text = Text1.text & vbCrLf & r
Else
d = CStr(rs!Date1) & vbCrLf
r = d & vbCrLf & (rs!chat_from) & vbCrLf & CStr(rs!Time1) & vbCrLf & (rs!messege)
Text1.text = Text1.text & vbCrLf & r
End If
rs.MoveNext
Wend

Text1.text = Text1.text & vbCrLf & vbCrLf & "so far " + CStr(cnt) + " msgs!!"
Text1.ForeColor = vbBlue
End If
End If
rs.Close
Set rs = Nothing
End Sub

Private Sub Command2_Click()
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "DELETE * from table2 WHERE(chat_from='" & Combo1.text & "' AND chat_to='" & Combo2.text & "') OR (chat_from='" & Combo2.text & "' AND chat_to='" & Combo1.text & "')", con, adOpenDynamic, adLockOptimistic
MsgBox ("Conversation deleted successfully")
Text1.text = ""
End Sub

Private Sub Command3_Click()
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open " DELETE * from table2", con, adOpenDynamic, adLockOptimistic
MsgBox ("All conversations deleted")
End Sub

Private Sub Form_Load()
Main ' for populating peer name
Set rs = New ADODB.Recordset
rs.Open "SELECT distinct chat_to FROM table2", con, adOpenDynamic, adLockOptimistic
While rs.EOF = False
Combo2.AddItem rs!chat_to
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
Main ' for populating my name
Set rs = New ADODB.Recordset
rs.Open "SELECT distinct chat_from FROM table2", con, adOpenDynamic, adLockOptimistic
While rs.EOF = False
Combo1.AddItem rs!chat_from
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
End Sub


